package com.qst.order.controller;


import com.qst.order.service.OSSService;
import com.qst.order.utils.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/api/upload")
@RequiredArgsConstructor
public class UploadController {


    private final OSSService ossService;


    //阿里云上传音乐相关接口
    @PostMapping
    public Result<String> proxyUpload(@RequestParam("file") MultipartFile file,
                                      @RequestParam("type") String type) {

        log.info("上传中........{}",type);
        log.info("上传中：{}",file);
        try {
            String url = ossService.uploadFile(file, type);
            return Result.success(url);
        } catch (Exception e) {
            // 推荐：使用 log.error() 并传入异常对象，自动打印堆栈信息
            log.error("上传错误消息：", e);
            return Result.error("上传失败: " + e.getMessage());
        }
    }

}
